package com.xbongbong.saas.script.tempenum;

import com.xbongbong.paas.domain.entity.ext.PaasFormEntityExt;
import com.xbongbong.paas.field.FieldAttrEntity;
import com.xbongbong.paas.field.LinkedAttrPoJo;
import com.xbongbong.paas.toolbox.util.BeanUtil;
import com.xbongbong.pro.enums.AmountFlagEnum;
import com.xbongbong.pro.enums.DistributorMarkEnum;
import com.xbongbong.pro.enums.SaasMarkEnum;
import com.xbongbong.paas.field.SaasParticularAttributePoJo;
import com.xbongbong.paas.field.LinkInfoPojo;
import com.xbongbong.paas.field.LinkKeyFieldInfoPojo;
import com.xbongbong.saas.enums.CustomerStatementDistributorEnum;
import com.xbongbong.saas.enums.CustomerStatementEnum;
import com.xbongbong.saas.enums.ForbiddenSettingEnum;
import com.xbongbong.saas.enums.RedundantTemplateTypeEnum;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * @Description
 * @author: shian
 * @date : 2021/1/11
 */
@Getter
public enum TempCustomerStatementDistributorEnum {
    //对账日期
    CHECKING_DATE(CustomerStatementDistributorEnum.CHECKING_DATE),
    BUSINESS_TYPE(CustomerStatementDistributorEnum.BUSINESS_TYPE),
    TYPE(CustomerStatementDistributorEnum.TYPE),
    STATEMENT_ID(CustomerStatementDistributorEnum.STATEMENT_ID),
    STATEMENT_NO(CustomerStatementDistributorEnum.STATEMENT_NO),
    CUSTOMER_ID(CustomerStatementDistributorEnum.CUSTOMER_ID),
    CUSTOMER_NAME(CustomerStatementDistributorEnum.CUSTOMER_NAME),
    CONTRACT_ID(CustomerStatementDistributorEnum.CONTRACT_ID),
    CONTRACT_NO(CustomerStatementDistributorEnum.CONTRACT_NO),
    SOURCE_TYPE(CustomerStatementDistributorEnum.SOURCE_TYPE),
    SOURCE_ID(CustomerStatementDistributorEnum.SOURCE_ID),
    SOURCE_NO(CustomerStatementDistributorEnum.SOURCE_NO),
    AMOUNT_RECEIVABLE(CustomerStatementDistributorEnum.AMOUNT_RECEIVABLE),
    AMOUNT_RECEIVED(CustomerStatementDistributorEnum.AMOUNT_RECEIVED),
    WRITE_OFF_AMOUNT(CustomerStatementDistributorEnum.WRITE_OFF_AMOUNT),
    BALANCE_RECEIVABLE(CustomerStatementDistributorEnum.BALANCE_RECEIVABLE),
    PAYMENT_TYPE(CustomerStatementDistributorEnum.PAYMENT_TYPE),
    PRODUCT(CustomerStatementDistributorEnum.PRODUCT),
    ADD_TIME(CustomerStatementDistributorEnum.ADD_TIME),
    UPDATE_TIME(CustomerStatementDistributorEnum.UPDATE_TIME),
    ;

    private CustomerStatementDistributorEnum anEnum;

    TempCustomerStatementDistributorEnum(CustomerStatementDistributorEnum anEnum) {
        this.anEnum = anEnum;
    }

    public static List<TempCustomerStatementDistributorEnum> getAllEnum() {
        List<TempCustomerStatementDistributorEnum> list = new ArrayList<>();
        Collections.addAll(list, values());
        return list;
    }

    public static void initCustomerId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CUSTOMER.getCode());
        fieldAttrEntity.setLinkedText(CUSTOMER_NAME.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setDisableListSort(1);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    public static void initContractId(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setLinkedType(RedundantTemplateTypeEnum.CONTRACT.getCode());
        fieldAttrEntity.setLinkedText(CONTRACT_NO.getAnEnum().getAttr());
        SaasParticularAttributePoJo saasParticularAttributePoJo = new SaasParticularAttributePoJo();
        saasParticularAttributePoJo.setMultiCheck(false);
        fieldAttrEntity.setSaasParticularAttributePoJo(saasParticularAttributePoJo);
        fieldAttrEntity.setIsForbidden(0);
        fieldAttrEntity.setDisableListSort(1);
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }

    public static void initAmountReceivable(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initAmountReceived(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initWriteOffAmount(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initBalanceReceivable(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setSummaryFlag(1);
        fieldAttrEntity.setAmountFlag(AmountFlagEnum.YES.getType());
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initPaymentType(FieldAttrEntity fieldAttrEntity) {
        fieldAttrEntity.setIsForbidden(0);
    }

    public static void initProduct(FieldAttrEntity fieldAttrEntity, List<LinkedAttrPoJo> linkedAttrPoJoList, List<LinkedAttrPoJo> linkedShowPoJoList, PaasFormEntityExt paasFormEntity){
        LinkInfoPojo linkInfoPojo = new LinkInfoPojo();
        linkInfoPojo.setLinkBusinessType(XbbRefTypeEnum.PRODUCT.getCode());
        linkInfoPojo.setLinkedAttr(linkedAttrPoJoList);
        linkInfoPojo.setLinkSaasMark(SaasMarkEnum.SAAS.getCode());
        linkInfoPojo.setLinkKey(linkedAttrPoJoList.get(0).getAttr());
        linkInfoPojo.setLinkFormId(paasFormEntity.getId());
        linkInfoPojo.setLinkMenuId(paasFormEntity.getMenuId());
        linkInfoPojo.setLinkAppId(paasFormEntity.getAppId());
        linkInfoPojo.setCondition(new ArrayList<>());
        LinkKeyFieldInfoPojo linkKeyFieldInfoPojo = new LinkKeyFieldInfoPojo();
        BeanUtil.copyProperties(linkedAttrPoJoList.get(0),linkKeyFieldInfoPojo);
        linkInfoPojo.setLinkKeyAttr(linkKeyFieldInfoPojo);
        linkInfoPojo.setLinkedShowAttr(linkedShowPoJoList);
        fieldAttrEntity.setLinkInfo(linkInfoPojo);
        fieldAttrEntity.setShowEditable(1);
        fieldAttrEntity.setForbiddenSettingList(Collections.singletonList(ForbiddenSettingEnum.DISABLE_VISIBLE_PERMISSION.getAlias()));
        fieldAttrEntity.setDistributorMark(DistributorMarkEnum.DISTRIBUTOR.getCode());
    }
}
